USE [texchange_db]
GO

/****** Object:  StoredProcedure [dbo].[SP_TransportTypesByCompany]    Script Date: 05/29/2011 19:49:51 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[SP_TransportTypesByCompany]
	@id  bigint=0,
	@language_id bigint = 0
	-- Add the parameters for the function here 
AS
BEGIN 
	Declare @SQLQuery AS NVarchar(4000)
	SET @SQLQuery = 'SELECT transporttype_id as id, UniversalType.parent_id, UniversalType.name FROM CJCompanyTransport'
	IF @language_id > 1
	BEGIN
		SET @SQLQuery = @SQLQuery + ' INNER JOIN UniversalType ON CJCompanyTransport.transporttype_id = UniversalType.parent_id'
	END
	ELSE
	BEGIN
		SET @SQLQuery = @SQLQuery + ' INNER JOIN UniversalType ON CJCompanyTransport.transporttype_id = UniversalType.id'
	END
	SET @SQLQuery = @SQLQuery + ' WHERE UniversalType.language_id = @language_id AND CJCompanyTransport.company_id=@id'
	Declare @ParamDefinition AS NVarchar(2000) 
	Set @ParamDefinition = ' 
			@id  bigint=0,
			@language_id bigint = 0'
	--INSERT INTO @Company
	--PRINT @SQLQuery
	Execute sp_Executesql @SQLQuery, @ParamDefinition,@id,@language_id
	RETURN
END

GO


